

package cn.shengchao.controler.query;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.shengchao.util.helper.LoginHelper;
import cn.shengchao.examstar.comment.acl.ports.repositories.IProductCommentRepository;
import cn.shengchao.examstar.comment.ohs.local.message.CommentStatistics;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "产品评论")
@Slf4j
@RestController
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/comment")
public class ProductCommentQueryController {

    @Autowired
    private IProductCommentRepository iProductCommentRepository;

    @SaIgnore
    @GetMapping
    @Operation(summary = "评论", description = "评论")
    public CommentStatistics getComment(@RequestParam long productId) {
        log.info("产品：{},用户：{}", productId, LoginHelper.getUserId());
        return new CommentStatistics(iProductCommentRepository.getCommentByProductId(productId));
    }
}
